#pragma once

namespace mg
{
	class Texture
	{
	public:
		Texture();
		virtual ~Texture();

		bool load(const char* filename, int desired_channels = 0, bool powerOfTwo = false, bool make_mipmaps = false, GLuint texId = 0, GLenum target = GL_TEXTURE_2D);

		void bind(int unit);

		GLuint detachTextureId(BYTE*& outData);

		void TexParameter(GLuint mag_filter = GL_LINEAR,
			GLuint min_filter = GL_LINEAR,
			GLuint wrap_s = GL_REPEAT,
			GLuint wrap_t = GL_REPEAT);

		const std::string& getName() { return m_name; }

		GLenum getTarget() { return m_target; }

		GLuint getTextureId() { return m_textureId; }

		int getWidth() { return m_width; }

		int getHeight() { return m_height; }

		unsigned int getChannels() { return m_channels; }

	protected:
		BYTE* convertPowerOfTwo(BYTE* data, int channels, int& width, int& height);

		GLenum m_target;
		GLuint m_textureId;
		std::string m_name;
		int m_width;
		int m_height;
		int m_channels;
		BYTE* m_data;
	};
}

extern "C"
{
	bool LoadTextureJpg_4563E0(const char* filepath, int texId, int filter, int wrap, const char* owner, BOOL need);
	bool LoadTextureTga_456830(const char* filepath, int texId, int filter, int wrap, const char* owner, BOOL need);
}
